package org.exam.blog.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.exam.blog.domain.Param;
import org.exam.blog.domain.Param;
import org.exam.blog.query.MessageQuery;
import org.exam.blog.service.IParamService;
import org.exam.blog.service.IParamService;
import org.exam.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping("/param")
@Api(tags = "用户提示")
public class ParamController {
    @ApiOperation(value = "查询单个接口")
    @PutMapping
    public JsonResult add(@RequestBody Param param) {
        try {
            if (param.getId() == null) {
                iParamService.add(param);
                return JsonResult.success();
            } else {
                iParamService.update(param);
                return JsonResult.success();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error();

        }
    }

    @Autowired
    private IParamService iParamService;

    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable Long id) {
        try {
            iParamService.delete(id);
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error();
        }
    }

    @GetMapping("/{id}")
    public Param get(@PathVariable("id") Long id) {
        return iParamService.get(id);
    }


    @PatchMapping
    public JsonResult patchDelete(@RequestBody Long[] ids) {
        try {
            iParamService.patchDelete(ids);
            return JsonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error();
        }
    }

    @PostMapping
    public PageInfo<Param> queryPage(@RequestBody MessageQuery messageQuery) {
        return iParamService.queryPage(messageQuery);
    }


    @GetMapping
    public List<Param> getAll() {
        return iParamService.getAll();
    }

    @GetMapping("/getParams")
    public Map<String, Object> get(){
        return iParamService.get();
    }
}





